package com.ym.manager.admin.banner;

import com.ym.manager.admin.banner.model.BannerInfo;
import com.ym.utils.Pages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BannerModel {

    @Autowired
    private BannerMapper bannerMapper;

    //查询banner列表数据
    public Pages<BannerInfo> listData(int pageNum, int limit, int placeId) {
        Map<String,Object> map = new HashMap<>();
        int begin = (pageNum-1)*limit;
        map.put("begin",begin);
        map.put("limit",limit);
        map.put("placeId",placeId);
        int count  = bannerMapper.getListCount(map);
        List<BannerInfo> list = bannerMapper.getList(map);
        Pages<BannerInfo> pages = new Pages<>(count,pageNum,limit);
        pages.setList(list);
        return pages;
    }

    //新增banner
    public int insert(BannerInfo bannerInfo) {
        bannerInfo.setIdx(bannerMapper.maxIdx());
        return bannerMapper.insert(bannerInfo);
    }

    //删除banner
    public int delete(int id) {
        return bannerMapper.delete(id);
    }
}
